<template>
  <div class="login">
    <div class="bg"></div>
    <form>
      <header>
        <img :src="logo" />
      </header>
      <div class="inputs">
        <input
          type="text"
          name=""
          placeholder="username or email"
          v-model="form.userName"
        />
        <input
          type="password"
          name=""
          placeholder="password"
          v-model="form.password"
        />

        <p class="light"><a href="#">忘记密码?</a></p>
      </div>
    </form>
    <footer>
      <button @click="login()">进入</button>
      <p>没有账号? <a href="#" @click="switchApp()">注册</a></p>
    </footer>
  </div>
</template>

<script>
import { reactive } from "vue";
import { useRouter } from "vue-router";
import { useStore } from "vuex";
import { loginAPI } from "../../api/user.api";

export default {
  name: "login-app",
  setup(props, { emit }) {
    const store = useStore();
    const router = useRouter();
    const form = reactive({
      userName: "000000",
      password: "000000",
    });

    const login = async () => {
      let data = await loginAPI(form);
      console.log(data);
      alert(data.msg);
      if (data.data !== undefined) {
        await store.dispatch("EDIT_USER_INFO", data.data);
        await router.push({
          path: "/",
        });
      }
    };
    const logo = require("../../assets/login/reading_0re1.svg");
    const switchApp = () => emit("switchApp", false);
    return {
      switchApp,
      login,
      form,
      logo,
    };
  },
};
</script>

<style scoped lang="scss">
img {
  max-width: 100%;
}

.login {
  background-color: #fff;
  width: 100vw;
  height: 100vh;
  border-radius: 5px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 6px 31px -2px rgba(0, 0, 0, 0.3);
  box-sizing: border-box;

  .bg {
    width: 130vw;
    height: 14rem;
    position: absolute;
    top: -15vh;
    left: 0;
    right: 0;
    margin: auto;
    background-image: url("../../assets/login/pngtree-blue.jpg");
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    -webkit-clip-path: ellipse(69% 46% at 48% 46%);
    clip-path: ellipse(69% 46% at 48% 46%);
  }
}

a {
  text-decoration: none;
  color: #257aa6;
}

p {
  font-size: 0.13rem;
  color: #333;
  line-height: 2;
}

.light {
  text-align: right;
  color: #fff;
}

.light a {
  color: #fff;
  font-size: $font-size-24;
}

form {
  position: relative;
  top: 0;
  left: 0;
  right: 0;
  width: 100vw;
  text-align: center;
  padding: 0.4rem;
  //padding-left: 0.1rem !important;
  box-sizing: border-box;
}

header {
  width: 6rem;
  height: 4.5rem;
  margin: 0.2rem auto;
}

.inputs {
  width: 100%;
  display: flex;
  flex-direction: column;

  input {
    font-size: $font-size-30;
    margin: 0.2rem 0rem;
    flex: 1;
    padding: 0.2rem 0.2rem;
    border-radius: 1rem;
    border: none;
    background: rgb(255, 255, 255, 0.3);
    font-family: "Poppins", sans-serif;
    outline: none;
    color: #fff;
  }

  input::placeholder {
    color: #fff;
    font-size: $font-size-30;
  }
}

footer {
  position: absolute;
  bottom: 0.3rem;
  left: 0;
  right: 0;
  padding: 0.2rem;
  text-align: center;

  button {
    font-size: $font-size-32;
    width: 100%;
    padding: 0.13rem 0.15rem;
    border-radius: 1rem;
    border: none;
    background: #257aa6;
    font-family: "Poppins", sans-serif;
    outline: none;
    color: #fff;
    font-weight: bold;
  }

  p {
    font-size: $font-size-24;
  }
}
</style>
